<?php require_once('../../Connections/Admin.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['user'])) {
  $loginUsername=$_POST['user'];
  $password=md5($_POST['pass']);
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "../";
  $MM_redirectLoginFailed = "login.php";
  $MM_redirecttoReferrer = true;
  mysql_select_db($database_Admin, $Admin);
  
  $LoginRS__query=sprintf("SELECT email, pass FROM users WHERE email=%s AND pass=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $Admin) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
	if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      

    if (isset($_SESSION['PrevUrl']) && true) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Iniciar Sesion</title>
<link href="../../css/AdminIndex.css" rel="stylesheet" type="text/css" media="screen">
<script src="../../SpryAssets/SpryTooltip.js" type="text/javascript"></script>
<link href="../../SpryAssets/SpryTooltip.css" rel="stylesheet" type="text/css">
</head>

<body><h2>Inicia sesión para modificar el subdominio de juventud</h2>
<form ACTION="<?php echo $loginFormAction; ?>" method="POST" name="loginForm" id="loginForm">
  <table>
    <tr>
      <th scope="row">Usuario</th>
      <td><input name="user" type="email" required id="email" autocomplete="on"></td>
    </tr>
    <tr>
      <th scope="row">Contraseña</th>
      <td><input name="pass" type="password" required autocomplete="on"></td>
    </tr>
    <tr>
      <th scope="row">&nbsp;</th>
      <td><input name="LogInForm" type="submit" value="Iniciar sesion" ></td>
    </tr>
    <tr>
      <th colspan="2" scope="row"><a href="reset.php">Recuperar contraseña</a></th>
    </tr>
  </table>
</form>
<div class="tooltipContent" id="sprytooltip1">Correo Electronico</div>
<script type="text/javascript">
var sprytooltip1 = new Spry.Widget.Tooltip("sprytooltip1", "#email", {followMouse:true, closeOnTooltipLeave:true, useEffect:"fade"});
</script>
</body>
</html>